<template>
  <div>
    <div class="block clearfix">
      <div class="option-type">{{tabName}}：</div>
      <div class="sub-options">
        <ul class="clearfix">
          <li
            v-for="(item ,index) in normalizedTabs"
            :key="index"
            @click="tabChange(tabName,index)"
          >
            <span :class="activeIndex == index ?'active' : ''">{{item.title}}</span>
          </li>
          <!-- <li>
            <span>内地</span>
          </li>
          <li>
            <span>港台</span>
          </li>
          <li>
            <span>欧美</span>
          </li>
          <li>
            <span>日本</span>
          </li>
          <li>
            <span>韩国</span>
          </li> -->
        </ul>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    tabs: {
      type: Array,
      default: () => []
    },
    tabName: {
      type: String
    }
  },
  name: "Tabsmy",
  data() {
    return {
      areaActiveIndex: 0,
      typeActiveIndex: 0,
      sortActiveIndex: 0,
      activeIndex: 0
    }
  },
  computed: {
    normalizedTabs() {
      return typeof this.tabs[0] === "string"
        ? this.tabs.map(tab => ({ title: tab }))
        : this.tabs
    }
  },
  methods: {
    tabChange(tabName, index) {
      if (tabName === '地区') {
        this.areaActiveIndex = index
        this.activeIndex = index
        this.$emit('input', this.areaActiveIndex)
      }
      if (tabName === '类型') {
        this.typeActiveIndex = index
        this.activeIndex = index
        this.$emit('input', this.typeActiveIndex)
      }
      if (tabName === '排序') {
        this.sortActiveIndex = index
        this.activeIndex = index
        this.$emit('input', this.sortActiveIndex)
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.block {
  min-width: 75rem;
  padding: 1rem 0;
  .option-type {
    float: left;
  }
  .sub-options {
    float: left;
    > ul {
      > li {
        float: left;
        padding: 0 1.4rem;
        border-right: 1px solid #e6e6fa;
        &:last-child {
          border-right: none;
        }
        > span {
          padding: 0.3rem 1.1rem;
          cursor: pointer;
        }
      }
    }
  }
}
.active {
  background-color: #ffc0cb;
  border-radius: 1rem;
  color: #dc143c;
}

.clearfix:after {
  content: ".";
  display: block;
  height: 0;
  visibility: hidden;
  clear: both;
}
</style>